//
//  TLCommentFrame.m
//  Coding_iOS
//
//  Created by taolei-mac on 2017/11/30.
//  Copyright © 2017年 com.lianchuan. All rights reserved.
//

#import "TLCommentFrame.h"
#import "TLComment.h"

@implementation TLCommentFrame

- (void)setComment:(TLComment *)comment
{
    _comment = comment;
    
    // 设置评论内容的frame
    CGFloat contentX = 10.0;
    CGFloat contentY = 10.0;
    CGSize resultSize = CGSizeZero;
    if (comment.content.length <= 0) {
        comment.content = @"  ";
    }
    CGSize maxSize = CGSizeMake(TLScreenW - contentX * 2 - 40, 200);
    NSMutableParagraphStyle *style = [NSMutableParagraphStyle new];
    style.lineBreakMode = NSLineBreakByWordWrapping;
    resultSize = [comment.content boundingRectWithSize:CGSizeMake(maxSize.width, maxSize.height)//用相对小的 width 去计算 height / 小 heigth 算 width
                                             options:(NSStringDrawingUsesLineFragmentOrigin)
                                          attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:14], NSParagraphStyleAttributeName: style}
                                             context:nil].size;
    if(resultSize.height > 200){
        resultSize.height = 200;
    }
    self.contentFrame = CGRectMake(contentX, contentY, maxSize.width, resultSize.height);
    
    // 设置评论时间的frame
    self.userFrame = CGRectMake(contentX, CGRectGetMaxY(self.contentFrame) + 10, 100, 13);
    
    self.cellHeight = CGRectGetMaxY(self.userFrame) + 10;
}

@end
